package org.example.juc.p16;

import java.util.concurrent.TimeUnit;

/**
 * @author lou ke
 * @since 2024/2/14 22:19
 * 守护线程
 */
public class DeamonThread {

    public static void main(String[] args) {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 100; i++) {
                    try {
                        TimeUnit.SECONDS.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        });

        // 设置子线程为守护线程
        thread.setDaemon(true);  // 主线程结束便结束了
        thread.start();

        System.out.println("主线程结束");

    }
}
